#include <stdio.h>
#include <stdlib.h>

int BinSearch(int a[], int n, int k)
{
    int low = 0, high = n - 1, mid;
    while (low <= high)
    {
        mid = (low + high) / 2;
        printf("%d ", a[mid]);
        if (k == a[mid])
            return a[mid + 1];
        if (k < a[mid])
            high = mid - 1;
        else
            low = mid + 1;
    }
    return 0;
}

int main()
{
    int array[] = {3, 6, 2, 10, 1, 8, 5, 7, 4, 9};
    printf("查找过程为:");
    int result = BinSearch(array, sizeof(array) / sizeof(array[0]), 9);
    return 0;
}